<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/WEB-INF/view/common/talent-header.jspf"%> 

	<ul class="nav nav-tabs" role="tablist">
	  <li role="presentation" class="active"><a href="<%=request.getContextPath()%>/CompanyServlet?command=main">审核</a></li>
	  <li role="presentation"><a href="<%=request.getContextPath()%>/PositionServlet?command=main">职位管理</a></li>
	</ul>

<div style="width:900px;margin:0 auto">
	<table class="table table-hover">
		<caption>
			<strong>审核管理：</strong>
		</caption>
		<thead>
			<tr>
				<td colspan="7">
					<form id="conditionForm" action="<%=request.getContextPath() %>/ApplicationServlet?command=listCompanyVerify" method="post">
						职位名称：<input type="text" name="positionName" value="${positionName }">
						审核状态：<select name="status">
									<option value="0" <c:if test="${status == 0}">selected=selected</c:if>>-全部-</option>
									<option value="1" <c:if test="${status == 1}">selected=selected</c:if>>待审核</option>
									<option value="2" <c:if test="${status == 2}">selected=selected</c:if>>已通过</option>
									<option value="3" <c:if test="${status == 3}">selected=selected</c:if>>已拒绝</option>
								</select>
						<button class="btn btn-primary">查询</button>
					</form>
				</td>
			</tr>
			<tr>
				<th>编号</th>
				<th>职位名称</th>
				<th>求职者</th>
				<th>简历信息</th>
				<th>申请时间</th>
				<th>审核状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:if test="${!empty pageModel.list }">
			<c:forEach items="${pageModel.list }" var="application" varStatus="v">
				<tr>
					<th scope="row">${v.count + (pageModel.pageNo-1)*pageModel.pageSize}</th>
					<td>${application.position$name }</td>
					<td>${application.talent$name }</td>
					<td><a href="<%=request.getContextPath()%>/ResumeServlet?command=companyRead&id=${application.resume$id}&talentId=${application.talent$id}">${application.resume$intention }</a></td>
					<td><fmt:formatDate value="${application.appTime }"
							pattern="yyyy-MM-dd HH:mm:ss" /></td>
					<td>
						<c:if test="${application.status == 1 }">
							${application.statusStr }
						</c:if>
						<c:if test="${application.status != 1 }">
							${application.statusStr }
							(<fmt:formatDate value="${application.handleTime }" pattern="yyyy-MM-dd HH:mm:ss" />)
						</c:if>
						
					</td>
					<td><a
						href="javascript:void(0);" onclick="verify(${application.id },this)">审核</a></td>
				</tr>
			</c:forEach>
		</c:if>
		<c:if test="${empty pageModel.list }">
			<tr>
		      	<td colspan="7" align="center">没有记录~</td>
			</tr>
		</c:if>
		</tbody>
	</table>
	<div class="pull-right">
			<button type="button" class="btn btn-default" onclick="submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerify&pageNo=${pageModel.first }')" <c:if test="${pageModel.pageNo==1 }"> disabled </c:if>>首页</button>
			<button type="button" class="btn btn-default" onclick="submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerify&pageNo=${pageModel.pre }')" <c:if test="${pageModel.pageNo==1 }"> disabled </c:if>>上一页</button>
			<select id="page" class="btn btn-default" onchange="goPage(this)"></select>
			<button type="button" class="btn btn-default" onclick="submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerify&pageNo=${pageModel.next }')" <c:if test="${pageModel.pageNo==pageModel.totalPage }"> disabled </c:if>>下一页</button>
			<button type="button" class="btn btn-default" onclick="submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerify&pageNo=${pageModel.last }')" <c:if test="${pageModel.pageNo==pageModel.totalPage }"> disabled </c:if>>尾页</button>
			&nbsp;&nbsp;&nbsp;&nbsp;总共${pageModel.allRecords }条记录
		</div>
</div>
<%@ include file="/WEB-INF/view/common/footer.jspf"%>
<script>
window.onload=function(){
	var pageNo='${pageModel.pageNo}';
	var totalPage='${pageModel.totalPage}';
	var s = document.getElementById("page");
	for (var i = 1; i <= totalPage; i++) {
		if(pageNo==i){
			 var varItem = new Option('第'+i+'页', i);      
		        s.options.add(varItem); 
		        varItem.selected=true;
		}else{
			var varItem = new Option('第'+i+'页', i);      
	        s.options.add(varItem); 
		}
	}
}

	
	/**
	 * 审核
	 */
	 function verify(applicationId,obj) {
	    //询问框
	    layer.confirm('通过还是拒绝？', {
	    	closeBtn: 0,
	        icon : 3,
	        btn: ['通过','拒绝'] //按钮
	    }, function(){
	        layer.msg('您选择了通过！', {icon: 1, time: 1000});
	        $.get("<%=request.getContextPath()%>/ApplicationServlet?command=verify&status=2&applicationId="+applicationId ,
	                function(text){
	        	$(obj).parent().prev().html("审核通过(" + text + ")");
	     	 });
	    }, function(){
	        layer.msg('您选择了拒绝！', {icon: 2, time: 1000});
	        $.get("<%=request.getContextPath()%>/ApplicationServlet?command=verify&status=3&applicationId="+applicationId ,
	                function(text){
	        	$(obj).parent().prev().html("已拒绝(" + text + ")");
	     	 });
	    });
	}
		/**
		 * 跳转到指定的页数
		 */
		function goPage(obj) {
			submitForm('<%=request.getContextPath()%>/ApplicationServlet?command=listCompanyVerify&pageNo=' + obj.value);
		}
		
		/**
		 * 分页时，使用JS使用表单
		 */
		function submitForm(url) {
			var conditionForm = document.getElementById('conditionForm');
			conditionForm.action = url;
			conditionForm.submit();
		}	
</script>